<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Liebao
 *
 * @author dragon.hu add @2016.3.10
 */
require_once 'BaseChannel.php';

//猎宝网
class Liebao implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="4f5765d2a131e81df783cde4d255a545"; //appkey
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; //秘钥
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("liebao", $_REQUEST);
		
		$orderid = $_REQUEST['orderid'];  //LB订单号
		$username = $_REQUEST['username'];  //LB登录账号
		$gameid = $_REQUEST['gameid'];  //游戏ID
		$roleid = $_REQUEST['roleid'];  //游戏角色ID
		$serverid = $_REQUEST['serverid'];  //服务器ID
		$paytype = $_REQUEST['paytype'];  //支付类型
		$amount = $_REQUEST['amount'];  //单位元
		$paytime = $_REQUEST['paytime'];  //充值时间
		$attach = $_REQUEST['attach'];  //拓展信息
		$sign = $_REQUEST['sign'];  //签名
		
		$mystr = "orderid=".urlencode($orderid)."&username=".urlencode($username)."&gameid=".urlencode($gameid)."&roleid=".urlencode($roleid)."&serverid=".urlencode($serverid).
		"&paytype=".urlencode($paytype)."&amount=".urlencode($amount)."&paytime=".urlencode($paytime)."&attach=".urlencode($attach)."&appkey=".urlencode($paymentKey);
		
		$mysign = md5($mystr);
		
		if($sign == $mysign)
		{ //验证通过
			 
			//进行发货
			if(false == $orderLog->recordOrder(STATUS_SUCCESS, $amount, $attach, "liebao", $platform,$orderid))
			{
				$ret="error";
				$orderLog->log("liebao",array("order"=>$attach,"money"=>$amount,"serverresult"=>"faild"));
			}else 
			{
				//支付成功
				$ret="success";
				$orderLog->log("liebao",array("order"=>$attach,"money"=>$amount,"serverresult"=>"success"));
			}
			 
		} else {
			//"$sig验证失败"
			$ret="errorSign";
			$orderLog->log("liebao","  order:$attach  sign error sign:$sign mysign:$mysign");
		}
		return $ret;
	}
	
}